<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>后台管理系统</title>
        <meta name="author" content="BaiYY"/>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
        <meta name="renderer" content="webkit">
        <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/bootstrap.min.css"/>
        <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/Font/css/font-awesome.min.css"/>
        <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/index.css"/>
        <script type="text/javascript" src="__PUBLIC__/admin/js/jquery.js"></script>
        <script type="text/javascript" src="__PUBLIC__/admin/js/bootstrap.min.js"></script>
        <script type="text/javascript" src="__PUBLIC__/admin/js/index.js"></script>
    </head>
    <body>
        <div class="right-sidebar" style="max-width: 1200px;">
            <ul class="nav nav-tabs" style="margin-bottom: 16px" role="tablist">
                <li role="presentation"><a href="agentUserRatio.html">后台返例设置</a></li>
                <li role="presentation" id="onLineRatio" class="active"><a href="onLineRatio.html">{:L(GAME_ONLINE_RATIO)}</a></li>
            </ul>
            <h3>说明:</h3>
            <p><strong>一级代理</strong>已是最高代理，只能自己享有返利</p>
            <p><strong>二级代理</strong>除自身享有返利外，还能向一级代理设置返利</p>
            <if condition="$level gt 2">
            <p><strong>三级代理</strong>除自身享有返利外，可以分别对一二级代理设置不同的返利</p>
            </if>
            <div class="row">
                <div class="form-group col-xs-12">
                    <div class="input-group">
                        <div class="input-group-addon">玩家对一级设置</div>
                        <input type="number" min="0" max="100" class="form-control" value="{$rebate1}" name="rebate1" id="rebate1">
                        <div class="input-group-addon">%</div>
                    </div>
                </div>
                <div class="form-group col-xs-12">
                    <div class="input-group">
                        <div class="input-group-addon">玩家对二级设置</div>
                        <input type="number" min="0" max="100" class="form-control" value="{$rebate2}" name="rebate2" id="rebate2">
                        <div class="input-group-addon">%</div>
                    </div>
                </div>
                <div class="form-group col-xs-12">
                    <div class="input-group">
                        <div class="input-group-addon">二级对一级设置</div>
                        <input type="number" min="0" max="100" class="form-control" value="{$srebate2}" name="srebate2" id="srebate2">
                        <div class="input-group-addon">%</div>
                    </div>
                </div>
                <if condition="$level gt 2">
                <div class="form-group col-xs-12">
                    <div class="input-group">
                        <div class="input-group-addon">玩家对三级设置</div>
                        <input type="number" min="0" max="100" class="form-control" value="{$rebate3}" name="rebate3" id="rebate3">
                        <div class="input-group-addon">%</div>
                    </div>
                </div>
                <div class="form-group col-xs-12">
                    <div class="input-group">
                        <div class="input-group-addon">三级对二级设置</div>
                        <input type="number" min="0" max="100" class="form-control" value="{$srebate3}" name="strebate3" id="srebate3">
                        <div class="input-group-addon">%</div>
                    </div>
                </div>
                <div class="form-group col-xs-12">
                    <div class="input-group">
                        <div class="input-group-addon">三级对一级设置</div>
                        <input type="number" min="0" max="100" class="form-control" value="{$trebate3}" name="trebate3" id="trebate3">
                        <div class="input-group-addon">%</div>
                    </div>
                </div>
                </if>
                <div class="col-xs-6"> <button type="submit" id="submit" class="btn btn-primary">设置</button></div>
            </div>
        </div>
        <script type="text/javascript">
            var onLineRatio = $.trim($("#onLineRatio").text());
            if(onLineRatio == '' || onLineRatio == 'GAME_ONLINE_RATIO') {
                $("#onLineRatio").hide();
            }
            $("#submit").on("click",function () {
                var rebate1 = $.trim($("#rebate1").val());
                var rebate2 = $.trim($("#rebate2").val());
                var srebate2 = $.trim($("#srebate2").val());
                var rebate3 = $.trim($("#rebate3").val());
                var srebate3 = $.trim($("#srebate3").val());
                var trebate3 = $.trim($("#trebate3").val());
                var level = "{$level}";
                var datas = '';
                if(level == 2) {
                    datas = {'rebate1':rebate1,'rebate2':rebate2,'srebate2':srebate2};
                    if(rebate1 == '' || rebate2 =='' || srebate2 == '') {
                        alert("任何一级设置不能为空");
                        window.location.href="{:U('Admin/Main/onLineRatio')}";
                        return false;
                    }

                    if(parseInt(rebate1) < 0 || parseInt(rebate2) < 0 || parseInt(srebate2) < 0) {
                        alert("代理比例不能小于0");
                        window.location.href = "{:U('Admin/Main/onLineRatio')}";
                        return false;
                    }

                    if(parseInt(rebate1) > 100 || parseInt(rebate2) > 100 || parseInt(srebate2) > 100) {
                        alert("代理比例不能大于100");
                        window.location.href = "{:U('Admin/Main/onLineRatio')}";
                        return false;
                    }
                }else{
                    datas = {'rebate1':rebate1,'rebate2':rebate2,'srebate2':srebate2,'rebate3':rebate3,'srebate3':srebate3,'trebate3':trebate3}

                    if(rebate1 == '' || rebate2 == '' || srebate2 == '' || rebate3 == '' || srebate3 == '' || trebate3 == '') {
                        alert("任何一级设置不能为空");
                        window.location.href="{:U('Admin/Main/onLineRatio')}";
                        return false;
                    }

                    if(parseInt(rebate1) < 0 || parseInt(rebate2) < 0 || parseInt(srebate2) < 0 || parseInt(rebate3) < 0 || parseInt(srebate3) < 0 || parseInt(trebate3) < 0) {
                        alert("代理比例不能小于0");
                        window.location.href = "{:U('Admin/Main/onLineRatio')}";
                        return false;
                    }

                    if(parseInt(rebate1) > 100 || parseInt(rebate2) > 100 || parseInt(srebate2) > 100 || parseInt(rebate3) > 100 || parseInt(srebate3) > 100 || parseInt(trebate3) > 100) {
                        alert("代理比例不能大于100");
                        window.location.href = "{:U('Admin/Main/onLineRatio')}";
                        return false;
                    }
                }
                $.ajax({
                    type:"post",
                    url:"{:U('Admin/Main/setOnlineRatio')}",
                    dataType:"json",
                    data:datas,
                    success: function (data) {
                       if(data == 'success') {
                           alert("设置成功！");
                           window.location.href="{:U('Admin/Main/onLineRatio')}";
                       }else if(data == 'error'){
                           alert("设置失败！");
                       }
                    }
                });
            });
        </script>
    </body>
</html>